package com.dz.service.impl;

import com.dz.bean.Guide;
import com.dz.bean.Visitor;
import com.dz.mapper.VisitorDao;
import com.dz.service.VisitorService;
import com.dz.util.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class VisitorServiceImpl implements VisitorService {

    @Autowired
    VisitorDao visitorDao;

    @Override
    public Visitor add(Visitor visitor) {
        visitorDao.add(visitor);
        Visitor result = visitorDao.findById(visitor.getId());
        return result;
    }

    @Override
    public int delete(Integer id) {
        return visitorDao.delete(id);
    }

    @Override
    public Visitor edit(Visitor visitor) {
        visitorDao.edit(visitor);
        Visitor result = visitorDao.findById(visitor.getId());
        return result;
    }

    @Override
    public List<Visitor> all(Visitor visitor) {
        return visitorDao.all(visitor);
    }

    @Override
    public Visitor findById(Integer id) {
        return visitorDao.findById(id);
    }

    @Override
    public void page(Page page, Visitor visitor) {
        int totalCount = visitorDao.pageCount(visitor);
        Object data = visitorDao.page(page,visitor);
        page.setTotalCount(totalCount);
        page.setData(data);
    }

    @Override
    public Visitor getByUsername(String username) {
        return visitorDao.getByUsername(username);
    }

    @Override
    public Visitor getByPhone(String phone) {
        return visitorDao.getByPhone(phone);
    }
}
